<?php 
	include_once '../common/header.php';
?>
<script>

function doLogin()
{
	var username = $("#txtUserName").val();
	var password = $("#txtPassword").val();

	var error = "";
	
	if(username.length==0)
	{
		error +="Username can not be blank.";
		error +="\n";
	}
	if(password.length==0)
	{
		error +="Password can not be blank.";
		error +="\n";
	}

	if(error.length!=0)
	{
		alert(error);
	}
	else
	{
		$.post("doLogin.php",{username:username,password:password},function(data){

			if(data!="0")
			{
				if(data==1) //user
				window.open("user-homepage.php");
				else if(data==2)
				window.open("admin/admin-homepage.php");
			}
			else
			{
				window.open("Login.php?message=failure",'_self');
			}
		},"text");
	}
}

</script>
<div class="body">
<!-- Login Area -->
<table width="1000" id="maintable" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td align="center">
<div id="popupContactAdminPage">
		<p id="contactArea">
		<?php //print $_SESSION["UserName"];?>
			<form id="frmLogin" name="frmLogin" method="post">
			<table cellpadding="2px" cellspacing="1px" bgcolor="#95A2AD" width="460px" class="tableBorder">
			    <tr>
			        <td colspan="2" bgcolor="#302C3B">&nbsp;</td>
			    </tr>
			    <tr>
			        <td colspan="2" class="label" align="center">
			        <label style="color: #F00;">
			        <?php 
			        if($_REQUEST['message']=="failure")
			        {
			        	echo "Wrong Username / Password. Please try again.";
			        }
			       
			        ?>
			        </label>
			        </td>
			    </tr>
			    <tr>
			        <td align="center" colspan="2">
			            <img src="images/lock.png" border="0" align="absbottom" height="25" width="25" />&nbsp;
			            <span class="message" style="color: navy;">Login to the System</span>
			        </td>
			    </tr>                  
			    <tr>
			        <td colspan="2" class="label">&nbsp;</td>
			        <label id="message"></label>
			    </tr>
			    <tr>
			        <td class="label" align="right" width="40%" style="color: navy">Username:</td>
			        <td align="left" width="60%"><input type="text" id="txtUserName" name="txtUserName" style="width: 160px;color: navy" maxlength="120"/></td>
			    </tr>
			    <tr>
			        <td class="label" align="right" style="color: navy">Password:</td>
			        <td align="left"><input type="password" name="txtPassword" id="txtPassword" maxlength="50" style="width: 160px;" /></td>
			    </tr>
			    <tr>
			    	<td colspan="2">&nbsp;</td>
			    </tr>
			    <tr>
			        <td align="center" colspan="2">
				        <input class="normalBtn" type="button" value="Login >>" id="btnLogin" name="btnLogin" onclick="doLogin();" />
				        <input class="normalBtn" type="reset" value="Reset >>" id="btnReset" name="btnReset" />
			        </td>
			    </tr>                  
			    
			    <tr>
			        <td colspan="2" class="label" align="right">
			        <div style="height: 6px;">&nbsp;</div>
			        <a href="password-reset.php" style="cursor: pointer;text-decoration: underline;font-size: 11px;font-family: Arial">Forgot Password?</a></td>
			    </tr>
			                      
			</table>			
			</form>
		</p>	
	</div>
</td>
</tr>
</table>
<!-- Login Area Ends -->
</div>

<?php 
  include_once '../common/footer.php';
?>